package com.bzxgc.sgwer.service.impl.project;

import com.bzxgc.sgwer.common.util.PageData;
import com.bzxgc.sgwer.dao.project.ProjectFunpointMapper;
import com.bzxgc.sgwer.entity.project.ProjectFunpoint;
import com.bzxgc.sgwer.service.project.ProjectFunpointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ProjectFunpointServiceImpl implements ProjectFunpointService {

    @Autowired
    private ProjectFunpointMapper projectFunpointMapper;

    @Override
    public void addProjectFunpoint(ProjectFunpoint projectFunpoint) {
        projectFunpoint.setAddTime(new Date());
        projectFunpoint.setStatus(1);
        projectFunpointMapper.addProjectFunpoint(projectFunpoint);
    }

    @Override
    public void updateProjectFunpoint(ProjectFunpoint projectFunpoint) {
        projectFunpoint.setUpdateTime(new Date());
        projectFunpointMapper.updateProjectFunpoint(projectFunpoint);
    }

    @Override
    public void updateProjectFunpointStatus(Long[] ids, Integer status) {
        projectFunpointMapper.updateProjectFunpointStatus(ids, status);
    }

    @Override
    public ProjectFunpoint getProjectFunpointById(Long id) {
        return projectFunpointMapper.getProjectFunpointById(id);
    }

    @Override
    public ProjectFunpoint getProjectFunpointByName(String name) {
        return projectFunpointMapper.getProjectFunpointByName(name);
    }

    @Override
    public List<ProjectFunpoint> getProjectFunpointList() {
        return projectFunpointMapper.getProjectFunpointList();
    }

    @Override
    public PageData<ProjectFunpoint> getProjectFunpointListByPage(Integer pageNum, Integer pageSize, String name) {
        List<ProjectFunpoint> projectFunpointList = projectFunpointMapper.getProjectFunpointListByPage(PageData.fromIndex(pageNum, pageSize), pageSize, name);
        Integer totalRecord = projectFunpointMapper.getProjectFunpointCount(name);
        PageData<ProjectFunpoint> pageData = new PageData<>(pageSize, pageNum, totalRecord, projectFunpointList);
        return pageData;
    }

    @Override
    public Integer getProjectFunpointCount(String name) {
        return projectFunpointMapper.getProjectFunpointCount(name);
    }

}
